using Godot;
using Godot.Collections;
using System;

public partial class TaskBar : MarginContainer
{
	public Button taskbutton;
	public VBoxContainer ChildTasks;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}

	public void Initialize()
	{
		var Game = GetNode<Game>("/root/Game");
		MessageManager messageManager = Game.get_message_manager();
		taskbutton = GetNode<Button>("%TaskButton");
		taskbutton.ButtonUp += () => messageManager.EmitSignal("ChooseTask",taskbutton.Text,"");
		ChildTasks = GetNode<VBoxContainer>("%ChildTasks");
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public void SetTaskName(string taskName)
	{

		taskbutton.Text = taskName;
	}
	public void AddChildTask(Array<Tasks> children)
	{
		var Game = GetNode<Game>("/root/Game");
		string ChildTasksPath = "res://components/task_component/ChildTask.tscn";
		
		foreach(Tasks child in children)
		{
			if(child.CurrentState != Tasks.State.WAITING)
			{continue;}
			ChildTask childTask = Game.InstantScene(ChildTasksPath) as ChildTask;
			ChildTasks.AddChild(childTask);
			childTask.Initialize();
			childTask.SetTaskName(child.name);
			
		}
	}

}
